//
//  DetailTableViewController.swift
//  私人通讯录
//
//  Created by zq on 2020/10/23.
//

import UIKit

class DetailTableViewController: UITableViewController {
    
    
    @IBOutlet weak var nameTextField: UITextField!
    
    @IBOutlet weak var phoneTextField: UITextField!
    
    @IBOutlet weak var titleTextField: UITextField!
    
    var person : Person?
    
    var complationResultCallBack: (()->())? //闭包是可选类型
    
    override func viewDidLoad() {
        super.viewDidLoad()
        
        if person != nil {
            nameTextField.text = person?.name
            phoneTextField.text = person?.phone
            titleTextField.text = person?.title
        }
    
    }
    
    
    @IBAction func save(_ sender: Any) {
        
        if person == nil {
            person = Person()
        }
        
        //保存数据
        person?.name = nameTextField.text
        person?.phone = phoneTextField.text
        person?.title = titleTextField.text
        //返回
        navigationController?.popViewController(animated: true)
        //返回之后上个页面刷新数据
        complationResultCallBack?() //如果闭包是nil,就不处理
    }
    
    

}
